﻿
namespace AdminApp.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.Web.DomainServices;
    using System.Web.DomainServices.Providers;
    using System.Web.Ria;
    using System.Web.Ria.Services;
    using AdminApp.Web;
    
    
    // Implements application logic using the DigitalSignageEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public partial class DigitalSignageDomainService : LinqToEntitiesDomainService<DigitalSignageEntities>
    {
        
        public IQueryable<AllSlots> GetAllSlots()
        {
            return this.ObjectContext.AllSlots;
        }
        
        [RequiresRole("Admins")]
        public void InsertEvent(Event @event)
        {
            if ((@event.EntityState != EntityState.Added))
            {
                if ((@event.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(@event, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.AddToEvent(@event);
                }
            }
        }

        [RequiresRole("Admins")]
        public void UpdateEvent(Event currentEvent)
        {
            if ((currentEvent.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentEvent, this.ChangeSet.GetOriginal(currentEvent));
            }
        }

        [RequiresRole("Admins")]
        public void DeleteEvent(Event @event)
        {
            if ((@event.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(@event);
            }
            this.ObjectContext.DeleteObject(@event);
        }
        
        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Room> GetRoom()
        {
            return this.ObjectContext.Room;
        }

        [RequiresRole("Admins")]
        public void InsertRoom(Room room)
        {
            if ((room.EntityState != EntityState.Added))
            {
                if ((room.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(room, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.AddToRoom(room);
                }
            }
        }

        [RequiresRole("Admins")]
        public void UpdateRoom(Room currentRoom)
        {
            if ((currentRoom.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentRoom, this.ChangeSet.GetOriginal(currentRoom));
            }
        }

        [RequiresRole("Admins")]
        public void DeleteRoom(Room room)
        {
            if ((room.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(room);
            }
            this.ObjectContext.DeleteObject(room);
        }
        
        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        //public IQueryable<Session> GetSession()
        //{
        //    return this.ObjectContext.Session;
        //}

        [RequiresRole("Admins")]
        public void InsertSession(Session session)
        {
            if ((session.EntityState != EntityState.Added))
            {
                if ((session.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(session, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.AddToSession(session);
                }
            }
        }

        [RequiresRole("Admins")]
        public void UpdateSession(Session currentSession)
        {
            if ((currentSession.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentSession, this.ChangeSet.GetOriginal(currentSession));
            }
        }

        [RequiresRole("Admins")]
        public void DeleteSession(Session session)
        {
            if ((session.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(session);
            }
            this.ObjectContext.DeleteObject(session);
        }
        
        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Slot> GetSlot()
        {
            return this.ObjectContext.Slot;
        }

        [RequiresRole("Admins")]
        public void InsertSlot(Slot slot)
        {
            if ((slot.EntityState != EntityState.Added))
            {
                if ((slot.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(slot, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.AddToSlot(slot);
                }
            }
        }

        [RequiresRole("Admins")]
        public void UpdateSlot(Slot currentSlot)
        {
            if ((currentSlot.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentSlot, this.ChangeSet.GetOriginal(currentSlot));
            }
        }

        [RequiresRole("Admins")]
        public void DeleteSlot(Slot slot)
        {
            if ((slot.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(slot);
            }
            this.ObjectContext.DeleteObject(slot);
        }
        
        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        //public IQueryable<Speaker> GetSpeaker()
        //{
        //    return this.ObjectContext.Speaker;
        //}

        [RequiresRole("Admins")]
        public void InsertSpeaker(Speaker speaker)
        {
            if ((speaker.EntityState != EntityState.Added))
            {
                if ((speaker.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(speaker, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.AddToSpeaker(speaker);
                }
            }
        }

        [RequiresRole("Admins")]
        public void UpdateSpeaker(Speaker currentSpeaker)
        {
            if ((currentSpeaker.EntityState == EntityState.Detached))
            {
                this.ObjectContext.AttachAsModified(currentSpeaker, this.ChangeSet.GetOriginal(currentSpeaker));
            }
        }

        [RequiresRole("Admins")]
        public void DeleteSpeaker(Speaker speaker)
        {
            if ((speaker.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(speaker);
            }
            this.ObjectContext.DeleteObject(speaker);
        }
    }
}


